
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link rel="stylesheet" href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" >
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
</head>
<body>

<div id="formArea">
	<table class="table">
		<tr>
			<td><label>所属机构</label></td>
			<td><div id="companyId"></div></td>
			<td><input type="text" class="input" placeholder="请输入商品名称 或编号 或条码" name="complex"/></td>
			<td>
				<button class="button" id="query"><span>查询</span></button>
				<button class="button" id="create"><span>新增</span></button>
				<button class="button" id="exportExcel"><span>导出</span></button>
				<button class="button" id="importExcel"><span>导入</span></button>
			</td>
		</tr>

	</table>
</div>

<div id="table"></div>

<script>
    var editArea = ['800px', '610px'];

    $(function(){
        $('#create').click(function(){
            app.window(layer,{
                title:'添加商品',
                area: editArea,
                content: 'product_add.html'
            });
        });

        $('#exportExcel').click(function () {
            var o = {loginUserId:top.loginUserId,customerId:top.customerId,loginCompanyId:top.loginCompanyId,loginCompanyLogicalCode:top.loginCompanyLogicalCode};
            var url = app.BASE_API_URL+'eexport/product?1=1';
            for( var n in o ){
                url += "&"+n+"="+o[n];
			}
            window.open(url, "_blank");
        });

        $('#query').click(function(){
            $("#table").datagrid("reload",app.serializeForm());
        });

        $('#importExcel').click(function(){
            app.window(layer,{
                title:'商品导入',
                area: ['500px', '300px'],
                content: './product_import.html'
            });
        });

        $('#companyId').search({
            name:'companyId',
            click:function () {
                app.window(layer,{
                    title:'供应商选择',
                    btn:[],
                    area: ['600px', '600px'],
                    content: '../../common/company_tree.html?index=-1&searchId=companyId'
                });
            }
        });

        $('#table').datagrid({
            url:app.BASE_API_URL+'product/page',
            columns:[
                {field:'name',title:'商品名称',width:100},
                {field:'code',title:'商品编码',width:100},
                {field:'barcode',title:'商品条码',width:100},
                {field:'productTypeName',title:'商品分类',width:120,fixed:true,style:{"text-align":"left","padding-left":"10px"}},
                {field:'unitName',title:'计量单位',width:50},
                {field:'companyName',title:'使用机构',width:100},
                {field:'model',title:'规格型号',width:100},
                {field:'purchasePrice',title:'进货价',width:70,n:'money'},
                {field:'salePrice',title:'销售价',width:70,n:'money'},
                {title:'操作',width:100,formatter:function(row){
					return [app.DEFAULT_ALL_VALUE,app.getOperation(row.id,'编辑','edit','edit'),app.getOperation(row.id,'删除','del','remove')];
				}}
            ]
        });
    });

    function remove(_this) {
        var id = $(_this).data('id');
        layer.confirm('确定要删除选中的记录吗？', {icon: 3, title:'提示'}, function(index){
            app.request({
                url:'product/delete',
                data:{id:id},
                success:function(resp){
                    if( resp.result==0 ){
                        app.message(layer,'操作成功');
                        $('#table').datagrid('reload');
                    }else{
                        app.message(layer,'操作失败【'+app.getErrorMessage(resp)+'】',2);
                    }
                    layer.close(index);
                }
            });

        });
    }

    function edit(_this) {
        var id = $(_this).data('id');
        app.window(layer,{
            area: editArea,
            content: 'product_add.html?id='+id
        });
    }
</script>

</body>
</html>